<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.4.4.min.js"></script>

</head>
<body>
	<a href="${pageContext.request.contextPath }/user/borrowlist">我的图书</a>
	欢迎用户:<span>${user.realName}</span>
	<div id="all">
		<form action="${pageContext.request.contextPath}/user/lists" method="post" name="frm">
		<div>
			<input type="text" name="bookName" value="${query.bookName}"><button onclick="sreach()">搜索</button>
			<input type="hidden" id="now" name="pageNow" value="${pb.pageNow}"/>
		</div>
		</form>
		<div id="list">
			<table width="800px" border="1px">
				<tr>
					<th>编号</th>
					<th>书名</th>
					<th>图片</th>
					<th>作者</th>
					<th>出版社</th>
					<th>剩余库存</th>
					<th>操作</th>
				</tr>
				<c:forEach var="list" items="${pb.lists}">
					<tr align="center">
						<td>${list.bid}</td>
						<td>${list.bookname }</td>
						<td>图片</td>
						<td>${list.writer}</td>
						<td>${list.press}</td>
						<td id="id_${list.bid}">${list.count}</td>
						<td><button onclick="jieshu(${list.bid})">借书</button></td>
					</tr>
				</c:forEach>
			</table>
		</div>
		<div id="page">
			当前页${pb.pageNow}/总页数${pb.pageCount}/总条数${pb.rowCount}　
			<button type="button" onclick="page(1)">首页</button>
			<button type="button" onclick="page(${pb.lastPage})">上一页</button>
			<button type="button" onclick="page(${pb.nextPage})">下一页</button>
			<button type="button" onclick="page(${pb.pageCount})">尾页</button>
			<input class="go" type="text" id="gopage"/><button type="button" onclick="gopage(this.value)">Go</button>
		</div>
	</div>
	<script type="text/javascript">
	function jieshu(bid){
		 var idValue = "id_"+bid;
		var count = $("#"+idValue).text();
		//var borrow = $("#borrow_"+bid).text();
		
		//alert(borrow);
		 if(parseInt(count) < 1){
			alert("库存不足");
			return;
		}else{
			$.post(
				"${pageContext.request.contextPath}/user/borrow",
				"bid="+bid,
				function(data){
					if(data == '1'){						
						alert("借书成功");
						$("#"+idValue).text(parseInt(count)-1);
					}else{
						alert("借书失败");
					}
				}				
			);
		}
	}
	function sreach(){
		$("#now").val(1);
		document.frm.submit();
	} 
	function page(i){
		$("#now").val(i);
		document.frm.submit();
		//location = '${pageContext.request.contextPath}/animal/animal_list?query.pageNow='+i;
	}
	function gopage(j){
		var j = document.getElementById("gopage").value;
		location = '${pageContext.request.contextPath}/user/lists?pageNow='+j;
	}
	</script>
</body>
</html>